﻿package mortal.game.view.common.guide
{
    import Message.DB.Tables.*;
    import Message.Game.*;
    import com.gengine.core.frame.*;
    import com.gengine.debug.*;
    import flash.utils.*;
    import mortal.common.global.*;
    import mortal.common.net.*;
    import mortal.component.gLinkText.*;
    import mortal.component.gconst.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.scene3D.ai.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.guide.data.*;
    import mortal.game.view.common.guide.navbar.*;
    import mortal.game.view.common.guide.stepOperater.*;
    import mortal.game.view.forging.view.*;
    import mortal.game.view.mainUI.Navbar.*;
    import mortal.game.view.pack.*;
    import mortal.game.view.shopMall.*;
    import mortal.game.view.systemSetting.*;
    import mortal.game.view.task.data.*;
    import mortal.game.view.task.drama.*;
    import mortal.mvc.core.*;

    public class AutoGuideController extends Controller
    {
        private var _canOpSteps:Dictionary;
        private var _guidingSteps:Dictionary;
        private var _sceneInited:Boolean = false;
        private var _taskGoted:Boolean = false;
        private var _systemSetterGot:Boolean = false;
        private var _winSteper:IAutoGuideSteper;
        private var _winRectSteper:IAutoGuideSteper;
        private var _iconSteper:IAutoGuideSteper;
        private var _backPackSteper:IAutoGuideSteper;
        private var _timerSteper:IAutoGuideSteper;
        private var _closeWinSteper:IAutoGuideSteper;
        private var _flyEffectSteper:IAutoGuideSteper;
        private var _pickUpItemSteper:IAutoGuideSteper;
        private var _eventSteper:IAutoGuideSteper;
        private var _layerSteper:IAutoGuideSteper;
        private var _tipsSteper:IAutoGuideSteper;
        private var _flyToRightDown:IAutoGuideSteper;
        private var _taskNextStepSteper:IAutoGuideSteper;
        private var _systemFunc:IAutoGuideSteper;
        private var _tweenTips:IAutoGuideSteper;
        private var _flyToWizard:IAutoGuideSteper;
        private var _loader:IAutoGuideSteper;
        private var _picture:IAutoGuideSteper;
        private var _playerRolling:IAutoGuideSteper;
        private var _newFuncSteper:IAutoGuideSteper;
        private var _waittingSubTypActiveList:Array;
        private var _guidingStep:IAutoGuideSteper;
        private var _guidingData:AutoGuideData;
        private var _guidingTime:int = -1;
        private var navbarUIShows:Array;
        private var _guideEndData:AutoGuideData;
        private var _lastShowedWin:Window;
        private var _lastCloseWin:BaseWindow;
        private var _recorder:AutoGuideStepRecorder;
        private static var _lastGuideTime:int = -100000;
        public static var _guidingMainId:int = -1;
        public static const NavbarUINames:Array = [ModuleType.ShopMall, ModuleType.Daily, ModuleType.Group, ModuleType.Friend, ModuleType.Guild, ModuleType.Build, ModuleType.Wizard, ModuleType.Skills, ModuleType.Pack, ModuleType.Players];
        public static var NavBarShowLvs:Array = [];
        public static var isUIRowIninted:Boolean = false;

        public function AutoGuideController()
        {
            this._waittingSubTypActiveList = [];
            this.navbarUIShows = [true, false, true, false, false, false, false, false, true, true];
            this._recorder = new AutoGuideStepRecorder();
            this.initUIShowLevel();
            return;
        }// end function

        override protected function initServer() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.RoleLevelUpdate, this.checkPlayerLevelupHandler);
            NetDispatcher.addCmdListener(ServerCommand.TaskDoingAdd, this.checkTaskDoingSingle);
            NetDispatcher.addCmdListener(ServerCommand.TaskUpdate, this.taskUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.TaskDoingDel, this.taskEndHandler);
            NetDispatcher.addCmdListener(ServerCommand.TaskDoingListRecv, this.taskDoingListGotHandler);
            Dispatcher.addEventListener(EventName.WindowShowed, this.checkWinShowedHandler);
            Dispatcher.addEventListener(EventName.WindowClosed, this.closeWinHandler);
            Dispatcher.addEventListener(EventName.AutoGuideStepEnd, this.stepEndHandler);
            Dispatcher.addEventListener(EventName.Scene_Update, this.sceneUpdateHandler);
            NetDispatcher.addCmdListener(ServerCommand.SystemClientSettingGot, this.onGotSysSetting);
            Dispatcher.addEventListener(EventName.AutoGuideActiveByEvent, this.activeByEventHandler);
            Dispatcher.addEventListener(EventName.AutoGuideEndByEvent, this.customEndStepHandler);
            Dispatcher.addEventListener(EventName.AutoGuideBreakGuide, this.breakGuideHandler);
            Dispatcher.addEventListener(EventName.AutoGuideStopCurStep, this.stopCurStepHandler);
            Dispatcher.addEventListener(EventName.AutoGuideDelDoingRecord, this.delDoingRecordHandler);
            Dispatcher.addEventListener(EventName.TaskTrackClickEvent, this.clickTaskTrackHandler);
            Dispatcher.addEventListener(EventName.AI_FightAIEnd, this.fightOnceEndHandler);
            return;
        }// end function

        private function stopCurStepHandler(event:DataEvent) : void
        {
            var _loc_2:Array = null;
            this._guidingData = null;
            if (this._guidingTime == -1 || FrameManager.flashFrame.getTime() - this._guidingTime <= 100)
            {
                return;
            }
            if (this._guidingStep != null)
            {
                _loc_2 = event.data as Array;
                if (_loc_2.indexOf(_guidingMainId) >= 0)
                {
                    this._guidingStep.stop();
                    this._guidingStep = null;
                    _guidingMainId = -1;
                }
            }
            return;
        }// end function

        public function hasGuideFCFL() : Boolean
        {
            return cache.role.roleInfo.level >= 20;
        }// end function

        public function hasGuideZXSZ() : Boolean
        {
            return this._recorder.getIsStepFinished(21, 0) || cache.role.roleInfo.level >= 5;
        }// end function

        public function hasGuideExploitBuy() : Boolean
        {
            return this._recorder.getIsStepFinished(44, 0);
        }// end function

        public function hasGuideHonorBuy() : Boolean
        {
            return this._recorder.getIsStepFinished(43, 0);
        }// end function

        public function hasGuideRolling() : Boolean
        {
            return this._recorder.getIsStepFinished(20, 0) || cache.role.roleInfo.level >= GameDefConfig.instance.getSystemOpenLevel(25);
        }// end function

        public function hasGuideEscort() : Boolean
        {
            return this._recorder.getIsStepFinished(42, 0) || cache.role.roleInfo.level >= 50;
        }// end function

        public function hasGuideJP() : Boolean
        {
            if (cache.role.roleInfo.level >= GameDefConfig.instance.getSystemOpenLevel(26))
            {
                return true;
            }
            return false;
        }// end function

        public function hasGuideMount() : Boolean
        {
            return this._recorder.getIsStepFinished(10, 0) || cache.role.roleInfo.level >= GameDefConfig.instance.getSystemOpenLevel(1);
        }// end function

        public function hasGuideFenJieEquip() : Boolean
        {
            return this._recorder.getIsStepFinished(17, 0) || this._recorder.getIsStepFinished(18, 0) || cache.role.roleInfo.level >= GameDefConfig.instance.getSystemOpenLevel(18);
        }// end function

        public function hasGuideWing() : Boolean
        {
            return this._recorder.getIsStepFinished(45, 0) || cache.role.roleInfo.level >= (GameDefConfig.instance.getSystemOpenLevel(67) + 1);
        }// end function

        public function hasGuideLevelReward() : Boolean
        {
            return cache.role.roleInfo.level >= GameDefConfig.instance.getSystemOpenLevel(23) || this._recorder.getIsStepFinished(22, 0);
        }// end function

        public function hasGuideChallengeCopy() : Boolean
        {
            return this._recorder.getIsStepFinished(16, 0) || Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(8);
        }// end function

        public function isGuidingQH() : Boolean
        {
            return _guidingMainId == 6;
        }// end function

        public function hasGuideQH() : Boolean
        {
            return this._recorder.getIsStepFinished(6, 0) || Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(3);
        }// end function

        public function hasGuidePet() : Boolean
        {
            return this._recorder.getIsStepFinished(3, 0) || Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(2);
        }// end function

        public function isGuidingVip() : Boolean
        {
            if (this._recorder == null)
            {
                return false;
            }
            var _loc_1:* = ClockManager.instance.nowDate.time / 1000 - ClientSetting.local.guideVipTime;
            if (_loc_1 >= 1800)
            {
                return false;
            }
            return true;
        }// end function

        public function isGuidingPetEgg() : Boolean
        {
            return this._recorder.getIsStepFinished(3, 0);
        }// end function

        public function hasGuideGroupCopy() : Boolean
        {
            return this._recorder.getIsStepFinished(31, 0) || Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(7);
        }// end function

        public function hasGuideCopyIcon() : Boolean
        {
            return this._recorder.getIsStepFinished(15, 0) || Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(6);
        }// end function

        public function hasGuideSingCopy() : Boolean
        {
            return this._recorder.getIsStepFinished(23, 0) || Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(6);
        }// end function

        public function hasGuideDefenseCopy() : Boolean
        {
            return this._recorder.getIsStepFinished(24, 0) || Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(9);
        }// end function

        public function hasTeamGuideDefenseCopy() : Boolean
        {
            return Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(59);
        }// end function

        public function get isGuidingWizard() : Boolean
        {
            return _guidingMainId == 8;
        }// end function

        public function get hasGuideWizard() : Boolean
        {
            return this.isGuidingWizard || this._recorder.getIsStepFinished(8, 0) || Cache.instance.role.entityInfo.level >= GameDefConfig.instance.getSystemOpenLevel(5);
        }// end function

        private function fightOnceEndHandler(event:DataEvent) : void
        {
            var _loc_3:AutoGuideData = null;
            var _loc_2:* = this._waittingSubTypActiveList.length - 1;
            while (_loc_2 >= 0)
            {
                
                _loc_3 = this._waittingSubTypActiveList[_loc_2];
                if (_loc_3.subType == AutoGuideActivedType.Sub_Fight)
                {
                    this.operateStep(_loc_3, null, true);
                    this._waittingSubTypActiveList.splice(_loc_2, 1);
                    AutoGuideCache.isWaittingFollowFightAI = false;
                }
                _loc_2 = _loc_2 - 1;
            }
            return;
        }// end function

        public function hasShowModule(param1:String) : Boolean
        {
            var _loc_2:* = NavbarUINames.indexOf(param1);
            if (_loc_2 < 0)
            {
                return false;
            }
            return NavbarButtonUIRow.instance.showStatusList[_loc_2] as Boolean;
        }// end function

        private function initUIShowLevel() : void
        {
            NavBarShowLvs[0] = -1;
            NavBarShowLvs[1] = GameDefConfig.instance.getSystemOpenLevel(24);
            NavBarShowLvs[2] = -1;
            NavBarShowLvs[3] = GameDefConfig.instance.getSystemOpenLevel(14);
            NavBarShowLvs[4] = GameDefConfig.instance.getSystemOpenLevel(4);
            NavBarShowLvs[5] = GameDefConfig.instance.getSystemOpenLevel(3);
            NavBarShowLvs[6] = GameDefConfig.instance.getSystemOpenLevel(5);
            NavBarShowLvs[7] = GameDefConfig.instance.getSystemOpenLevel(0);
            NavBarShowLvs[8] = GameDefConfig.instance.getSystemOpenLevel(4);
            NavBarShowLvs[9] = -1;
            NavBarShowLvs[10] = -1;
            return;
        }// end function

        private function initNavbarUIShows() : void
        {
            var _loc_1:int = 0;
            var _loc_2:int = 0;
            var _loc_3:Array = null;
            var _loc_4:AutoGuideData = null;
            var _loc_5:int = 0;
            if (!this.isUIByLevel)
            {
                _loc_1 = 0;
                while (_loc_1 < this.navbarUIShows.length)
                {
                    
                    this.navbarUIShows[_loc_1] = true;
                    _loc_1++;
                }
            }
            else
            {
                _loc_2 = cache.role.roleInfo.level;
                _loc_3 = AutoGuideConfig.instance.getConfigs(["guideType"], [AutoGuideType.FlyToRightDownIcon]);
                _loc_3 = _loc_3.concat(AutoGuideConfig.instance.getConfigs(["guideType", "clickChildName"], [AutoGuideType.FlyToRightDownIcon, AutoGuideClickType.SaveRightDownIconShowed]));
                if (_loc_3 == null || _loc_3.length == 0)
                {
                    return;
                }
                for each (_loc_4 in _loc_3)
                {
                    
                    _loc_5 = NavbarUINames.indexOf(_loc_4.guideTypeValue as String);
                    if (_loc_5 < 0)
                    {
                        continue;
                    }
                    this.navbarUIShows[_loc_5] = this._recorder.getIsStepFinished(_loc_4.mainId, (_loc_4.stepId - 1));
                }
            }
            NavbarButtonUIRow.instance.init((GameController.navbar.view as NavbarModule).btnBottomContainer, NavbarUINames);
            this.checkNavIconShowByLevel(true);
            return;
        }// end function

        private function checkNavIconShowByLevel(param1:Boolean = false) : void
        {
            var _loc_2:* = cache.role.roleInfo.level;
            var _loc_3:Boolean = false;
            var _loc_4:int = 0;
            while (_loc_4 < NavBarShowLvs.length)
            {
                
                if (this.navbarUIShows[_loc_4] == false && _loc_2 >= NavBarShowLvs[_loc_4])
                {
                    this.navbarUIShows[_loc_4] = true;
                    _loc_3 = true;
                }
                _loc_4++;
            }
            if (param1 || _loc_3)
            {
                NavbarButtonUIRow.instance.initShow(this.navbarUIShows);
            }
            return;
        }// end function

        public function get isUIByLevel() : Boolean
        {
            if (!ParamsConst.instance.isUIByLevel || cache.role.roleInfo.level >= 70)
            {
                return false;
            }
            return true;
        }// end function

        public function addSubType(param1:AutoGuideData) : void
        {
            this._waittingSubTypActiveList.push(param1);
            if (param1.subType == AutoGuideActivedType.Sub_Fight)
            {
                AutoGuideCache.isWaittingFollowFightAI = true;
            }
            return;
        }// end function

        public function delSubType(param1:AutoGuideData) : void
        {
            var _loc_3:AutoGuideData = null;
            var _loc_2:* = this._waittingSubTypActiveList.indexOf(param1);
            if (_loc_2 >= 0)
            {
                this._waittingSubTypActiveList.splice(_loc_2, 1);
            }
            var _loc_4:Boolean = false;
            var _loc_5:int = 0;
            while (_loc_5 < this._waittingSubTypActiveList.length)
            {
                
                _loc_3 = this._waittingSubTypActiveList[_loc_5];
                if (_loc_3.subType == AutoGuideActivedType.Sub_Fight)
                {
                    _loc_4 = true;
                    break;
                }
                _loc_5++;
            }
            if (!_loc_4)
            {
                AutoGuideCache.isWaittingFollowFightAI = false;
            }
            return;
        }// end function

        public function checkAndStopGuideShopMallWhenTabed() : void
        {
            if (this._guidingData == null)
            {
                return;
            }
            if (this._guidingData.mainId == 14)
            {
                if (this._guidingData.stepId != 2)
                {
                    this.customEndStepHandler(null);
                }
                else if ((GameController.shopMall.view as ShopMallModule).getSelectedIndex() != 3)
                {
                    this.customEndStepHandler(null);
                }
            }
            else if (this._guidingData.mainId == 44)
            {
                if (this._guidingData.stepId != 2)
                {
                    this.customEndStepHandler(null);
                }
                else if ((GameController.shopMall.view as ShopMallModule).getSelectedIndex() != 5)
                {
                    this.customEndStepHandler(null);
                }
            }
            return;
        }// end function

        public function operateStep(param1:AutoGuideData, param2:Window = null, param3:Boolean = false) : void
        {
            var _loc_5:int = 0;
            if (!param3 && param1.isSubActiveType())
            {
                this.addSubType(param1);
                this._guidingData = param1;
                return;
            }
            this.recorder.addDoingStep(param1.mainId, param1.stepId);
            var _loc_4:* = this.getSteper(param1);
            if (_loc_4 == null)
            {
                return;
            }
            this._guidingData = param1;
            if (!param1.noBreakAI && !TaskDramaOperator.isInFlyDrama)
            {
                AIManager.cancelAll();
            }
            if (!param1.noGuidingStatus)
            {
                _lastGuideTime = getTimer();
                Dispatcher.dispatchEvent(new DataEvent(EventName.HideTaskDialog));
            }
            else
            {
                _lastGuideTime = -1111111;
            }
            if (param1.subType != AutoGuideData.NoStopOtherGuide)
            {
                if (this._guidingStep != null)
                {
                    this._guidingStep.stop();
                }
                _guidingMainId = param1.mainId;
                this._guidingStep = _loc_4;
            }
            _loc_4.guide(param1, param2);
            this._guidingTime = FrameManager.flashFrame.getTime();
            if (param1.mainId == 13 && param1.stepId == 1)
            {
                _loc_5 = ClockManager.instance.nowDate.time / 1000;
                ClientSetting.local.guideVipTime = _loc_5;
                ClientSetting.save();
            }
            if (param1.mainId == 17 && param1.clickChildName == "Equip_decomposeBtn")
            {
                EquipDecomposePanel.guiding = true;
            }
            return;
        }// end function

        private function breakStep(param1:AutoGuideData) : void
        {
            this.recorder.delDoingId(param1.mainId);
            var _loc_2:* = this.getSteper(param1);
            if (_loc_2 == null)
            {
                return;
            }
            if (param1.guideType == AutoGuideType.TweenTips)
            {
                _loc_2.stop(param1);
            }
            else
            {
                _loc_2.stop();
            }
            return;
        }// end function

        private function getSteper(param1:AutoGuideData) : IAutoGuideSteper
        {
            var _loc_2:IAutoGuideSteper = null;
            switch(param1.guideType)
            {
                case AutoGuideType.RightDownIcon:
                {
                    _loc_2 = this.iconSteper;
                    break;
                }
                case AutoGuideType.Window:
                {
                    _loc_2 = this.winSteper;
                    break;
                }
                case AutoGuideType.WindowRect:
                {
                    _loc_2 = this.winRectSteper;
                    break;
                }
                case AutoGuideType.BackPack:
                {
                    _loc_2 = this.backPackSteper;
                    break;
                }
                case AutoGuideType.Timer:
                {
                    _loc_2 = this.timerSteper;
                    break;
                }
                case AutoGuideType.CloseWin:
                {
                    _loc_2 = this.closeWinSteper;
                    break;
                }
                case AutoGuideType.FlyEffect:
                {
                    _loc_2 = this.flyEffectSteper;
                    break;
                }
                case AutoGuideType.PickUpItem:
                {
                    _loc_2 = this.pickUpItemSteper;
                    break;
                }
                case AutoGuideType.DispatchEvent:
                {
                    _loc_2 = this.eventSteper;
                    break;
                }
                case AutoGuideType.Layer:
                {
                    _loc_2 = this.layerSteper;
                    break;
                }
                case AutoGuideType.RollingTips:
                {
                    _loc_2 = this.tipsSteper;
                    break;
                }
                case AutoGuideType.FlyToRightDownIcon:
                {
                    _loc_2 = this.flyToRightDownSteper;
                    break;
                }
                case AutoGuideType.EndGuide:
                {
                    _loc_2 = this.taskEndGuideSteper;
                    break;
                }
                case AutoGuideType.systemFunc:
                {
                    _loc_2 = this.systemFuncSteper;
                    break;
                }
                case AutoGuideType.NewFunc:
                {
                    _loc_2 = this.newFuncSteper;
                    break;
                }
                case AutoGuideType.TweenTips:
                {
                    _loc_2 = this.tweenTips;
                    break;
                }
                case AutoGuideType.FlyToWizardIcon:
                {
                    _loc_2 = this.flyToWizard;
                    break;
                }
                case AutoGuideType.loadRes:
                {
                    _loc_2 = this.loader;
                    break;
                }
                case AutoGuideType.Picture:
                {
                    _loc_2 = this.picture;
                    break;
                }
                case AutoGuideType.PlayerRolling:
                {
                    _loc_2 = this.playerRolling;
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return _loc_2;
        }// end function

        private function breakGuideHandler(event:DataEvent) : void
        {
            this._guidingData = null;
            var _loc_2:* = event.data as AutoGuideData;
            if (_loc_2 == null)
            {
                return;
            }
            this.breakStep(_loc_2);
            if (_loc_2.mainId == _guidingMainId && this._guidingStep != null)
            {
                this._guidingStep = null;
                _guidingMainId = -1;
            }
            return;
        }// end function

        private function delDoingRecordHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as AutoGuideData;
            if (_loc_2 == null)
            {
                return;
            }
            this.recorder.delDoingId(_loc_2.mainId);
            return;
        }// end function

        private function clickTaskTrackHandler(event:DataEvent) : void
        {
            var _loc_4:TaskInfo = null;
            var _loc_5:TTaskGuide = null;
            var _loc_6:Array = null;
            var _loc_7:AutoGuideData = null;
            var _loc_8:int = 0;
            var _loc_2:* = event.data as Array;
            var _loc_3:* = _loc_2[1] as GLinkTextData;
            if (_loc_3.type == "GuideTask_StartFromRecord")
            {
                _loc_4 = _loc_3.data as TaskInfo;
                if (_loc_4 == null)
                {
                    return;
                }
                _loc_5 = TaskConfig.instance.getTaskGuideByTask(_loc_4.stask.code.toString(), _loc_4.curStep);
                if (_loc_5 == null)
                {
                    Log.error("自动指引找不到任务的指引：taskId = " + _loc_4.stask.code + ", step = " + _loc_4.curStep);
                    return;
                }
                _loc_6 = AutoGuideConfig.instance.getConfigs(["guideActivedType", "guideActivedTypeValue"], [AutoGuideActivedType.TaskDoing, _loc_5.id]);
                for each (_loc_7 in _loc_6)
                {
                    
                    _loc_8 = this.recorder.getDoingStep(_loc_7.mainId);
                    _loc_7 = AutoGuideConfig.instance.getConfigs(["mainId", "stepId"], [_loc_7.mainId, _loc_8])[0] as AutoGuideData;
                    if (_loc_7 == null)
                    {
                        continue;
                    }
                    this.breakStep(_loc_7);
                    this.operateStep(_loc_7);
                    break;
                }
            }
            return;
        }// end function

        private function stepEndHandler(event:DataEvent) : void
        {
            this._guidingStep = null;
            _guidingMainId = -1;
            this._guidingData = null;
            this._guideEndData = event.data as AutoGuideData;
            if (this._guideEndData == null)
            {
                return;
            }
            this.recorder.addDoneStep(this._guideEndData.mainId, this._guideEndData.stepId);
            this.recorder.delDoingId(this._guideEndData.mainId);
            this.recorder.addCurDonStep(this._guideEndData.mainId, this._guideEndData.stepId);
            this.checkAndSaveCacheName(this._guideEndData);
            _lastGuideTime = -111111;
            CallLater.addCallBack(this.nextFrameWhenGuideEnd);
            return;
        }// end function

        private function nextFrameWhenGuideEnd() : void
        {
            if (this.checkNextStepGuide() || this.checkPreMainType())
            {
                return;
            }
            if (this._guideEndData.filterName == AutoGuideData.NoMainEndType)
            {
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.AutoGuideMainEnd, this._guideEndData));
            return;
        }// end function

        private function onGotSysSetting(event:DataEvent) : void
        {
            NetDispatcher.removeCmdListener(ServerCommand.SystemClientSettingGot, this.onGotSysSetting);
            this._systemSetterGot = true;
            this.checkAllInitedHandler();
            return;
        }// end function

        private function customEndStepHandler(event:DataEvent) : void
        {
            this._guidingData = null;
            if (this._guidingStep != null)
            {
                this._guidingStep.stop();
                this._guidingStep = null;
                _guidingMainId = -1;
            }
            return;
        }// end function

        private function activeByEventHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data;
            var _loc_3:* = _loc_2["mainId"];
            var _loc_4:* = _loc_2["stepId"];
            var _loc_5:* = AutoGuideConfig.instance.getConfigs(["mainId", "stepId"], [_loc_3, _loc_4]);
            if (_loc_5 == null || _loc_5.length == 0)
            {
                return;
            }
            var _loc_6:* = _loc_5[0];
            var _loc_7:* = _loc_6.clone();
            ClassTypesUtil.copyValue(_loc_7, _loc_2);
            this.operateStep(_loc_7, null, true);
            return;
        }// end function

        private function sceneUpdateHandler(event:DataEvent) : void
        {
            Dispatcher.removeEventListener(EventName.Scene_Update, this.sceneUpdateHandler);
            this._sceneInited = true;
            this.checkAllInitedHandler();
            return;
        }// end function

        private function taskDoingListGotHandler(param1:Object) : void
        {
            this._taskGoted = true;
            this.checkAllInitedHandler();
            return;
        }// end function

        private function checkAllInitedHandler() : void
        {
            if (!this._systemSetterGot || !this._sceneInited || !this._taskGoted)
            {
                return;
            }
            NetDispatcher.removeCmdListener(ServerCommand.TaskDoingListRecv, this.taskDoingListGotHandler);
            this.recorder.init();
            this.initNavbarUIShows();
            isUIRowIninted = true;
            Dispatcher.dispatchEvent(new DataEvent(EventName.NavbarButtonUIRowInited));
            return;
        }// end function

        private function checkPlayerLevelupHandler(param1:Object) : void
        {
            var _loc_2:AutoGuideData = null;
            var _loc_3:Array = null;
            var _loc_5:String = null;
            var _loc_6:TSystemTrailer = null;
            this.checkNavIconShowByLevel();
            var _loc_4:* = cache.role.roleInfo.level;
            _loc_3 = AutoGuideConfig.instance.getConfigs(["guideActivedType"], [AutoGuideActivedType.LevelUp_Func]);
            for each (_loc_2 in _loc_3)
            {
                
                _loc_5 = String(_loc_2.guideTypeValue);
                _loc_6 = FuncPreCofonfig.instance.getConfigBySystem(_loc_5);
                if (_loc_6 != null && _loc_6.level == _loc_4)
                {
                    if (CopyUtil.isInCopy && _loc_2.mainId == GameConst.GuideTowerCopyMainId)
                    {
                        cache.copy.guideWhenLeaveCopy = _loc_2.mainId;
                        return;
                    }
                    this.operateStep(_loc_2);
                    return;
                }
            }
            _loc_3 = AutoGuideConfig.instance.getConfigs(["guideActivedType", "guideActivedTypeValue"], [AutoGuideActivedType.LevelUp, _loc_4]);
            if (_loc_3 == null || _loc_3.length == 0)
            {
                return;
            }
            for each (_loc_2 in _loc_3)
            {
                
                if (!this.canIOperateStep(_loc_2))
                {
                    continue;
                }
                this.operateStep(_loc_2);
            }
            return;
        }// end function

        private function checkNextStepGuide(param1:Boolean = false) : Boolean
        {
            var _loc_3:AutoGuideData = null;
            if (this._guideEndData == null)
            {
                return false;
            }
            var _loc_2:* = AutoGuideConfig.instance.getConfigs(["mainId", "guideActivedType"], [this._guideEndData.mainId, AutoGuideActivedType.PreGuideStep]);
            if (_loc_2 == null || _loc_2.length == 0)
            {
                return false;
            }
            for each (_loc_3 in _loc_2)
            {
                
                if (!this.canIOperateStep(_loc_3))
                {
                    continue;
                }
                if (param1)
                {
                    if (!this.hasNextsNeedSaveStep(_loc_3))
                    {
                        continue;
                    }
                }
                else if ((this.recorder.getCurDoneStep(_loc_3.mainId) + 1) != _loc_3.stepId)
                {
                    continue;
                }
                this.operateStep(_loc_3);
                return true;
            }
            return false;
        }// end function

        private function checkPreMainType(param1:Boolean = false) : Boolean
        {
            var _loc_3:AutoGuideData = null;
            var _loc_4:Array = null;
            var _loc_5:AutoGuideData = null;
            var _loc_6:int = 0;
            var _loc_7:Array = null;
            var _loc_8:AutoGuideData = null;
            var _loc_2:* = AutoGuideConfig.instance.getConfigs(["guideActivedType"], [AutoGuideActivedType.PreMain]);
            if (_loc_2 == null || _loc_2.length == 0)
            {
                return false;
            }
            for each (_loc_3 in _loc_2)
            {
                
                if (!this.canIOperateStep(_loc_3))
                {
                    continue;
                }
                _loc_4 = AutoGuideConfig.instance.getConfigs(["mainId"], [int(_loc_3.guideActivedTypeValue)]);
                if (_loc_4 != null)
                {
                    _loc_5 = _loc_4[0] as AutoGuideData;
                }
                if (_loc_5 == null)
                {
                    continue;
                }
                _loc_6 = this.recorder.getDoneStep(_loc_5.mainId);
                _loc_7 = AutoGuideConfig.instance.getConfigs(["mainId", "stepId"], [_loc_5.mainId, (_loc_6 + 1)]);
                if (_loc_7 != null)
                {
                    _loc_8 = _loc_7[0] as AutoGuideData;
                }
                if (_loc_8 != null && this.hasNextsNeedSaveStep(_loc_8))
                {
                    continue;
                }
                if (param1)
                {
                    if (!this.hasNextsNeedSaveStep(_loc_3))
                    {
                        continue;
                    }
                }
                else if (_loc_8 != null)
                {
                    continue;
                }
                this.operateStep(_loc_3);
                return true;
            }
            return false;
        }// end function

        private function taskEndHandler(param1:Object) : void
        {
            var _loc_4:Array = null;
            var _loc_5:AutoGuideData = null;
            var _loc_2:* = param1 as TaskInfo;
            if (_loc_2 == null || _loc_2.stask == null)
            {
                return;
            }
            var _loc_3:* = TaskConfig.instance.getTaskGuideByTask(_loc_2.stask.code.toString(), _loc_2.curStep);
            if (_loc_3 != null)
            {
                _loc_4 = AutoGuideConfig.instance.getConfigs(["guideActivedType", "guideActivedTypeValue"], [AutoGuideActivedType.TaskDoing, _loc_3.id]);
                for each (_loc_5 in _loc_4)
                {
                    
                    if (_loc_5.isSaveStep == false)
                    {
                        continue;
                    }
                    this.recorder.saveStepDone(_loc_5.mainId, _loc_5.stepId);
                }
            }
            _loc_3 = TaskConfig.instance.getTaskGuideByTask(_loc_2.stask.code.toString(), _loc_2.curStep, true);
            if (_loc_3 == null)
            {
                return;
            }
            _loc_4 = AutoGuideConfig.instance.getConfigs(["guideActivedType", "guideActivedTypeValue"], [AutoGuideActivedType.TaskDoing, _loc_3.id]);
            for each (_loc_5 in _loc_4)
            {
                
                if (!this.canIOperateStep(_loc_5))
                {
                    continue;
                }
                if (_loc_5.subType == AutoGuideData.TaskEndNotEndGuide)
                {
                    continue;
                }
                this.operateStep(_loc_5);
            }
            return;
        }// end function

        private function taskUpdateHandler(param1:Object) : void
        {
            var _loc_4:SPlayerTaskUpdate = null;
            var _loc_5:TaskInfo = null;
            var _loc_6:TTaskGuide = null;
            var _loc_7:TTaskGuide = null;
            var _loc_8:Array = null;
            var _loc_9:AutoGuideData = null;
            var _loc_2:* = param1 as Array;
            if (_loc_2 == null || _loc_2.length == 0)
            {
                return;
            }
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2.length)
            {
                
                _loc_4 = _loc_2[_loc_3] as SPlayerTaskUpdate;
                _loc_5 = cache.task.getTaskByCode(_loc_4.taskCode);
                if (_loc_5 == null || _loc_5.stask == null)
                {
                }
                else if (_loc_5.curStep == _loc_5.lastStep)
                {
                }
                else
                {
                    _loc_6 = TaskConfig.instance.getTaskGuideByTask(_loc_5.stask.code.toString(), _loc_5.lastStep);
                    _loc_7 = TaskConfig.instance.getTaskGuideByTask(_loc_5.stask.code.toString(), _loc_5.curStep);
                    if (_loc_6 != null)
                    {
                        _loc_8 = AutoGuideConfig.instance.getConfigs(["guideActivedType", "guideActivedTypeValue"], [AutoGuideActivedType.TaskDoing, _loc_6.id]);
                        for each (_loc_9 in _loc_8)
                        {
                            
                            if (_loc_9.isSaveStep == false)
                            {
                                continue;
                            }
                            if (!_loc_5.isComplete())
                            {
                                continue;
                            }
                            this.recorder.saveStepDone(_loc_9.mainId, _loc_9.stepId);
                        }
                    }
                    if (_loc_7 != null)
                    {
                        _loc_8 = AutoGuideConfig.instance.getConfigs(["guideActivedType", "guideActivedTypeValue"], [AutoGuideActivedType.TaskDoing, _loc_7.id]);
                        for each (_loc_9 in _loc_8)
                        {
                            
                            if (!this.canIOperateStep(_loc_9))
                            {
                                continue;
                            }
                            this.operateStep(_loc_9);
                        }
                    }
                }
                _loc_3++;
            }
            return;
        }// end function

        private function checkTaskDoingSingle(param1:int) : void
        {
            var _loc_4:AutoGuideData = null;
            var _loc_2:* = cache.task.getTaskByCode(param1);
            if (_loc_2 == null || _loc_2.stask == null)
            {
                return;
            }
            var _loc_3:* = TaskConfig.instance.getTaskGuideByTask(_loc_2.stask.code.toString(), _loc_2.curStep);
            if (_loc_3 != null)
            {
                _loc_4 = AutoGuideConfig.instance.getConfigs(["guideActivedType", "guideActivedTypeValue"], [AutoGuideActivedType.TaskDoing, _loc_3.id])[0];
                if (_loc_4 != null)
                {
                    if (!this.canIOperateStep(_loc_4))
                    {
                        return;
                    }
                    this.operateStep(_loc_4);
                }
            }
            return;
        }// end function

        private function checkTaskDoingWhenRefresh() : void
        {
            var _loc_2:AutoGuideData = null;
            var _loc_3:int = 0;
            var _loc_4:TTaskGuide = null;
            var _loc_5:TaskInfo = null;
            if (!this._sceneInited || !this._taskGoted)
            {
                return;
            }
            var _loc_1:* = AutoGuideConfig.instance.getConfigs(["guideActivedType"], [AutoGuideActivedType.TaskDoing]);
            for each (_loc_2 in _loc_1)
            {
                
                _loc_3 = int(_loc_2.guideActivedTypeValue);
                _loc_4 = TaskConfig.instance.getTaskGuide(_loc_3);
                if (_loc_4 == null)
                {
                    continue;
                }
                _loc_5 = this.getTaskInfo(_loc_4.taskId);
                if (_loc_5 == null || _loc_5.curStep != _loc_4.step)
                {
                    continue;
                }
                if (_loc_2.refreshNotGuide)
                {
                    continue;
                }
                if (!this.canIOperateStep(_loc_2))
                {
                    continue;
                }
                if (!this.hasNextsNeedSaveStep(_loc_2))
                {
                    continue;
                }
                this.operateStep(_loc_2);
            }
            return;
        }// end function

        private function checkWinShowedHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as Window;
            if (_loc_2 == null || !_loc_2.hasOwnProperty("winTitleName"))
            {
                return;
            }
            this._lastShowedWin = _loc_2;
            setTimeout(this.nextFrameAfterWinShowed, 200);
            return;
        }// end function

        private function nextFrameAfterWinShowed() : void
        {
            var _loc_3:Array = null;
            var _loc_4:AutoGuideData = null;
            var _loc_5:TTaskGuide = null;
            var _loc_6:TaskInfo = null;
            if (this._lastShowedWin == null)
            {
                return;
            }
            var _loc_1:* = this._lastShowedWin;
            var _loc_2:* = _loc_1["winTitleName"];
            if (this._lastShowedWin is PackModule)
            {
                _loc_3 = AutoGuideConfig.instance.getConfigs(["guideType"], [AutoGuideType.BackPack]);
            }
            else
            {
                _loc_3 = AutoGuideConfig.instance.getConfigs(["guideType", "guideTypeValue"], [AutoGuideType.Window, _loc_2]);
                _loc_3 = _loc_3.concat(AutoGuideConfig.instance.getConfigs(["guideType", "guideTypeValue"], [AutoGuideType.WindowRect, _loc_2]));
            }
            if (_loc_3 == null || _loc_3.length == 0)
            {
                return;
            }
            for each (_loc_4 in _loc_3)
            {
                
                if (_loc_4.guideActivedType == AutoGuideActivedType.Event)
                {
                    continue;
                }
                if (_loc_4.guideActivedType == AutoGuideActivedType.TaskDoing)
                {
                    _loc_5 = TaskConfig.instance.getTaskGuide(int(_loc_4.guideActivedTypeValue));
                    if (_loc_5 == null)
                    {
                        continue;
                    }
                    _loc_6 = this.getTaskInfo(_loc_5.taskId);
                    if (_loc_6 == null || _loc_6.curStep != _loc_5.step)
                    {
                        continue;
                    }
                }
                if (!this.canIOperateStep(_loc_4))
                {
                    continue;
                }
                if (!this.hasNextsNeedSaveStep(_loc_4))
                {
                    continue;
                }
                if (_loc_4.subType == "needPre")
                {
                    _loc_4 = AutoGuideConfig.instance.getConfigs(["mainId", "stepId"], [_loc_4.mainId, (_loc_4.stepId - 1)])[0];
                    if (_loc_4 != null && _loc_4.subType == "needPre")
                    {
                        _loc_4 = AutoGuideConfig.instance.getConfigs(["mainId", "stepId"], [_loc_4.mainId, (_loc_4.stepId - 1)])[0];
                        if (_loc_4 != null && _loc_4.subType == "needPre")
                        {
                            _loc_4 = AutoGuideConfig.instance.getConfigs(["mainId", "stepId"], [_loc_4.mainId, (_loc_4.stepId - 1)])[0];
                            if (_loc_4 != null && _loc_4.subType == "needPre")
                            {
                                _loc_4 = AutoGuideConfig.instance.getConfigs(["mainId", "stepId"], [_loc_4.mainId, (_loc_4.stepId - 1)])[0];
                            }
                        }
                    }
                }
                if (_loc_4 != null)
                {
                    this.operateStep(_loc_4, _loc_1);
                }
                return;
            }
            this._lastShowedWin = null;
            return;
        }// end function

        private function getTaskInfo(param1:String) : TaskInfo
        {
            var _loc_2:TaskInfo = null;
            var _loc_3:* = param1.split("#");
            var _loc_4:int = 0;
            while (_loc_4 < _loc_3.length)
            {
                
                _loc_2 = cache.task.getTaskByCode(int(_loc_3[_loc_4]), true);
                if (_loc_2 != null)
                {
                    return _loc_2;
                }
                _loc_4++;
            }
            return null;
        }// end function

        private function closeWinHandler(event:DataEvent) : void
        {
            var _loc_2:* = event.data as BaseWindow;
            if (_loc_2 == null)
            {
                return;
            }
            this._lastCloseWin = _loc_2;
            setTimeout(this.nextFrameAfterWinClose, 110);
            return;
        }// end function

        private function nextFrameAfterWinClose() : void
        {
            var _loc_3:* = undefined;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:Array = null;
            var _loc_8:AutoGuideData = null;
            if (this._lastCloseWin == null)
            {
                return;
            }
            var _loc_1:* = this.recorder.doingStes;
            var _loc_2:Array = [];
            for (_loc_3 in _loc_1)
            {
                
                _loc_5 = int(_loc_3);
                _loc_6 = int(_loc_1[_loc_3]);
                if (_loc_6 <= 0)
                {
                    continue;
                }
                _loc_7 = AutoGuideConfig.instance.getConfigs(["mainId", "stepId"], [_loc_5, _loc_6]);
                if (_loc_7 == null || _loc_7.length == 0)
                {
                    continue;
                }
                _loc_8 = _loc_7[0];
                if (_loc_8.guideType == AutoGuideType.BackPack)
                {
                    _loc_2.push(_loc_5);
                    continue;
                }
                if (String(_loc_8.guideTypeValue) != this._lastCloseWin.winTitleName)
                {
                    if (_loc_8.guideType == AutoGuideType.Window)
                    {
                        _loc_2.push(_loc_5);
                        continue;
                    }
                    if (_loc_8.guideType == AutoGuideType.WindowRect)
                    {
                        _loc_2.push(_loc_5);
                    }
                }
            }
            _loc_4 = 0;
            while (_loc_4 < _loc_2.length)
            {
                
                this.recorder.delDoingId(int(_loc_2[_loc_4]));
                _loc_4++;
            }
            this._lastCloseWin = null;
            return;
        }// end function

        private function canIOperateStep(param1:AutoGuideData) : Boolean
        {
            if (param1 == null)
            {
                return false;
            }
            if (this.recorder.getDoneStep(param1.mainId) >= param1.stepId)
            {
                return false;
            }
            if (param1.stepId == this.recorder.getDoingStep(param1.mainId) && _guidingMainId == param1.mainId && isGuiding)
            {
                return false;
            }
            var _loc_2:* = this.recorder.getDoneStep(param1.mainId);
            if ((_loc_2 + 1) != param1.stepId)
            {
                return false;
            }
            return true;
        }// end function

        private function hasNextsNeedSaveStep(param1:AutoGuideData) : Boolean
        {
            var _loc_3:AutoGuideData = null;
            if (param1 == null)
            {
                return false;
            }
            var _loc_2:* = AutoGuideConfig.instance.getConfigs(["mainId"], [param1.mainId]);
            for each (_loc_3 in _loc_2)
            {
                
                if (_loc_3.stepId >= param1.stepId && _loc_3.isSaveStep)
                {
                    return true;
                }
            }
            return false;
        }// end function

        private function checkAndSaveCacheName(param1:AutoGuideData) : void
        {
            if (param1 == null || !param1.isSaveStep)
            {
                return;
            }
            this.recorder.saveStepDone(param1.mainId, param1.stepId);
            return;
        }// end function

        private function get winSteper() : IAutoGuideSteper
        {
            if (this._winSteper == null)
            {
                this._winSteper = new AutoGuideWindowSteper();
            }
            return this._winSteper;
        }// end function

        private function get winRectSteper() : IAutoGuideSteper
        {
            if (this._winRectSteper == null)
            {
                this._winRectSteper = new AutoGuideWinRectSteper();
            }
            return this._winRectSteper;
        }// end function

        private function get iconSteper() : IAutoGuideSteper
        {
            if (this._iconSteper == null)
            {
                this._iconSteper = new AutoGuideRightDownIconSteper();
            }
            return this._iconSteper;
        }// end function

        private function get backPackSteper() : IAutoGuideSteper
        {
            if (this._backPackSteper == null)
            {
                this._backPackSteper = new AutoGuideBackPackSteper();
            }
            return this._backPackSteper;
        }// end function

        private function get timerSteper() : IAutoGuideSteper
        {
            if (this._timerSteper == null)
            {
                this._timerSteper = new AutoGuideTimerSteper();
            }
            return this._timerSteper;
        }// end function

        private function get closeWinSteper() : IAutoGuideSteper
        {
            if (this._closeWinSteper == null)
            {
                this._closeWinSteper = new AutoGuideCloseWinSteper();
            }
            return this._closeWinSteper;
        }// end function

        public function get flyEffectSteper() : IAutoGuideSteper
        {
            if (this._flyEffectSteper == null)
            {
                this._flyEffectSteper = new AutoGuideFlyEffectSteper();
            }
            return this._flyEffectSteper;
        }// end function

        private function get pickUpItemSteper() : IAutoGuideSteper
        {
            if (this._pickUpItemSteper == null)
            {
                this._pickUpItemSteper = new AutoGuidePickUpItemSteper();
            }
            return this._pickUpItemSteper;
        }// end function

        private function get eventSteper() : IAutoGuideSteper
        {
            if (this._eventSteper == null)
            {
                this._eventSteper = new AutoGuideEventSteper();
            }
            return this._eventSteper;
        }// end function

        private function get layerSteper() : IAutoGuideSteper
        {
            if (this._layerSteper == null)
            {
                this._layerSteper = new AutoGuideLayerSteper();
            }
            return this._layerSteper;
        }// end function

        private function get tipsSteper() : IAutoGuideSteper
        {
            if (this._tipsSteper == null)
            {
                this._tipsSteper = new AutoGuideRollingTipsSteper();
            }
            return this._tipsSteper;
        }// end function

        private function get flyToRightDownSteper() : IAutoGuideSteper
        {
            if (this._flyToRightDown == null)
            {
                this._flyToRightDown = new AutoGuideFlyToRightDownIcon();
            }
            return this._flyToRightDown;
        }// end function

        private function get taskEndGuideSteper() : IAutoGuideSteper
        {
            if (this._taskNextStepSteper == null)
            {
                this._taskNextStepSteper = new AutoGuideEndGuideSteper();
            }
            return this._taskNextStepSteper;
        }// end function

        private function get playerRolling() : IAutoGuideSteper
        {
            if (this._playerRolling == null)
            {
                this._playerRolling = new AutoGuidePlayerRolling();
            }
            return this._playerRolling;
        }// end function

        private function get systemFuncSteper() : IAutoGuideSteper
        {
            if (this._systemFunc == null)
            {
                this._systemFunc = new AutoGuideSystemFuncSteper();
            }
            return this._systemFunc;
        }// end function

        private function get newFuncSteper() : IAutoGuideSteper
        {
            if (this._newFuncSteper == null)
            {
                this._newFuncSteper = new AutoGuideNewFuncSteper();
            }
            return this._newFuncSteper;
        }// end function

        private function get tweenTips() : IAutoGuideSteper
        {
            if (this._tweenTips == null)
            {
                this._tweenTips = new AutoGuideTweenTips();
            }
            return this._tweenTips;
        }// end function

        private function get flyToWizard() : IAutoGuideSteper
        {
            if (this._flyToWizard == null)
            {
                this._flyToWizard = new AutoGuideFlyToWizard();
            }
            return this._flyToWizard;
        }// end function

        private function get loader() : IAutoGuideSteper
        {
            if (this._loader == null)
            {
                this._loader = new AutoGuideLoadResSteper();
            }
            return this._loader;
        }// end function

        private function get picture() : IAutoGuideSteper
        {
            if (this._picture == null)
            {
                this._picture = new AutoGuidePicture();
            }
            return this._picture;
        }// end function

        public function get recorder() : AutoGuideStepRecorder
        {
            return this._recorder;
        }// end function

        public function hasGuideMainId(param1:int) : Boolean
        {
            return this._recorder.getIsStepFinished(param1, 0);
        }// end function

        public function checkAndStopGuiding() : void
        {
            if (_guidingMainId == 46 || _guidingMainId == 47)
            {
                this.customEndStepHandler(null);
            }
            return;
        }// end function

        public static function get isGuiding() : Boolean
        {
            if (getTimer() - _lastGuideTime <= 10000)
            {
                return true;
            }
            return false;
        }// end function

    }
}
